package com.javabi.htmlbuilder.html.element;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLElementList;
import com.javabi.htmlbuilder.html.HTMLElementName;

/**
 * An HTML Anchor Element.
 * <p>
 * &lt;anchor&gt; ... &lt;/anchor&gt;
 * </p>
 */
public class Anchor extends HTMLElementList<Anchor> {

	/** The reference. */
	private String href = null;
	/** The name. */
	private String name = null;
	/** The target. */
	private String target = null;

	/**
	 * Creates a new anchor.
	 * @param href the reference
	 */
	public Anchor(String href) {
		this.href = href;
	}

	/**
	 * Creates a new anchor.
	 */
	public Anchor() {
	}

	/**
	 * Returns the href
	 * @return the href
	 */
	public String getHref() {
		return href;
	}

	/**
	 * Sets the href
	 * @param href the href to set
	 */
	public void setHref(String href) {
		this.href = href;
	}

	/**
	 * Returns the name
	 * @return the name
	 */
	public String getName() {
		return href;
	}

	/**
	 * Sets the name
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Returns the target
	 * @return the target
	 */
	public String getTarget() {
		return target;
	}

	/**
	 * Sets the target
	 * @param target the target to set
	 */
	public void setTarget(String target) {
		this.target = target;
	}

	@Override
	public HTMLBuilder appendAttributesTo(HTMLBuilder html) {
		if (href != null) {
			html.attribute("href", href);
		}
		if (name != null) {
			html.attribute("name", name);
		}
		if (target != null) {
			html.attribute("target", target);
		}
		return html;
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public HTMLElementName getElementName() {
		return HTMLElementName.ANCHOR;
	}

}
